package com.library.utils
{
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.System;
	import flash.system.fscommand;
	
	public class ExternalLink
	{
		public function ExternalLink()
		{
			super();
		}
		
		public static function sendMail(isWeb:Boolean, receiver:String, subject:String="", body:String=""):void{
			if(isWeb){	
				if(subject == "" || body == ""){
					ExternalInterface.call("sendmailSimple", receiver);
				}else{
					ExternalInterface.call("sendmail", receiver, subject, body);
				}			
			}else{
				var dest:String = "mailto:"+receiver;
				if(subject != ""){
					dest += "?"+"subject="+subject;
					if(body != ""){
						dest += "&"+"body="+body;
					}
				}else{
					if(body != ""){
						dest += "?"+"body="+body;
					}
				}				
				navigateToURL(new URLRequest(dest));
				
			}
			//Logger.debug("sendMail: " + receiver);
		}		
		
		public static function getUrl(isWeb:Boolean, url:String, target:String = "_blank"):void{
			if(isWeb){
				//ExternalInterface.call("getURL", url, target);
				navigateToURL(new URLRequest(url),target);
			}else{
				navigateToURL(new URLRequest(url),target);
			}
			//Logger.debug("getUrl: " + url);
		}
		
		public static function openFullWindow(isWeb:Boolean, url:String, target:String = "_blank"):void{
			if(isWeb){
				ExternalInterface.call("openFullWindow", url, target);
			}else{
				navigateToURL(new URLRequest(url),target);;
			}
			//Logger.debug("openFullWindow: " + url);
		}
		
		public static function closeWindow(isWeb:Boolean, ):void{
			if(isWeb){
				ExternalInterface.call("closewindow");
			}
		}
		
		public static function exit():void{
			//fscommand("quit");
			System.exit(0);
		}
		
	}
}